<style>
    .layui-input-inline{margin-top:10px;}
</style>
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>数据分析</cite></a>
    <a><cite>代理商分润排行</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-tab layui-tab-brief">
      <ul class="layui-tab-title">
        <li class="layui-this">代理商分润排行</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <div class="layui-row" style="margin-bottom: 10px;">
            <div class="layui-form" style="float:right;">
              <div id="timeDiv" class="layui-form-item" style="margin:0;">
                <div class="layui-input-inline">
	                <input type="text" name="agentId" id="agentId" placeholder="代理商ID" autocomplete="off" class="layui-input">
	              </div>
	              <div class="layui-input-inline">
	                <select name="bizType" id="bizType" lay-search="">
	                  <option value="">业务类型</option>
	                  <option value="1">支付</option>
	                  <option value="4">充值</option>
	                  <option value="6">代付</option>
	                </select>
	              </div>
                  <a id="search" class="layui-btn" style="margin-top: 10px" data-type="reload"><i class="layui-icon layui-icon-search"></i>搜索</a>
              </div>
            </div>
          </div>

          <table id="XxPay_Bcd_User_dataAll" lay-filter="XxPay_Bcd_User_dataAll"></table>
        </div>

      </div>
    </div>
  </div>
</div>

<script>
layui.use(['admin', 'table', 'util', 'timePick'], function(){
  var $ = layui.$
  ,admin = layui.admin
  ,table = layui.table
  ,element = layui.element
  ,timePick = layui.timePick
  ,form = layui.form;

  timePick.init();  //第一个参数表示开始时间   第二个表示结束时间   0,0今天   -1,-1昨天   -7,0近一周   以此类推
  element.render('breadcrumb', 'breadcrumb');

  var tplOutAmount2 = function(d){
    return d.outAmount - d.feeAmount;
  };

  var createTimeStart = $('#createTimeStart').val();
  var createTimeEnd = $('#createTimeEnd').val();

    //统计列表
  table.render({
    elem: '#XxPay_Bcd_User_dataAll'
    ,cellMinWidth: 90
    ,url: layui.setter.baseUrl + '/data/count4AgentTop'
    ,where: {
      access_token: layui.data(layui.setter.tableName).access_token,
      createTimeStart: createTimeStart,
      createTimeEnd: createTimeEnd
    }
    ,initSort: {
      field: 'totalAgentProfit' //排序字段，对应 cols 设定的各字段名
      ,type: 'desc' //排序方式  asc: 升序、desc: 降序、null: 默认排序
    }
    ,id: 'tableReload'
    ,page: false
    ,cols: [[
      {field: 'agentId', title: '代理商ID'}
      ,{field: 'agentName', title: '代理商名称'}
      ,{field: 'totalAgentProfit', title: '分润金额', sort: true, templet: '<div>{{ d.totalAgentProfit/100 }}</div>'}
      ,{field: 'totalAmount', title: '金额', sort: true, templet: '<div>{{ d.totalAmount/100 }}</div>'}
      ,{field: 'totalCount', sort: true, title: '笔数'}
    ]]
    ,skin: 'line'
  });

  // 搜索
  var $ = layui.$, active = {
    reload: function(){
      var agentId = $('#agentId').val();
      var bizType = $('#bizType').val();
      var createTimeStart = $('#createTimeStart').val();
      var createTimeEnd = $('#createTimeEnd').val();
      //执行重载
      table.reload('tableReload', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,page: false
        ,where: {
          agentId: agentId,
          bizType: bizType,
          createTimeStart: createTimeStart,
          createTimeEnd: createTimeEnd
        }
      });
    }
  };
  $('#search').on('click', function() {
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });

  // 渲染表单
  form.render();
});
</script>